package data;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Cell {
	private final Slide parent;
	private final ArrayList<Cluster> clusters, cytoClusters, memClusters;
	private final Set<Focus> foci, cytoFoci, memFoci;
	
	public Cell(Slide parent, List<? extends Cluster> clusters) {
		this(parent);
		for (Cluster c : clusters) {
			addCluster(c);
		}
	}
	
	public Cell(Slide parent) {
		this.parent = parent;
		this.clusters = new ArrayList<Cluster>();
		this.cytoClusters = new ArrayList<Cluster>();
		this.memClusters = new ArrayList<Cluster>();
		this.foci = new HashSet<Focus>();
		this.cytoFoci = new HashSet<Focus>();
		this.memFoci = new HashSet<Focus>();
	}
	
	public Slide getParent() {
		return parent;
	}
	
	public int getTotalNumLabels() {
		int val = 0;
		for (Cluster c : getClusters()) {
			val += c.getNumLabels();
		}
		return val;
	}
	
	public List<Cluster> getClusters() {
		return clusters;
	}
	
	public List<Cluster> getMembraneClusters() {
		return Collections.unmodifiableList(memClusters);
	}
	
	public List<Cluster> getCytoplasmicClusters() {
		return Collections.unmodifiableList(cytoClusters);
	}
	
	public Set<Focus> getFoci() {
		return Collections.unmodifiableSet(foci);
	}
	
	public Set<Focus> getMembraneFoci() {
		return Collections.unmodifiableSet(memFoci);
	}
	
	public Set<Focus> getCytoplasmicFoci() {
		return Collections.unmodifiableSet(cytoFoci);
	}
	
	public void addCluster(Cluster c) {
		if (this.equals(c.getParent())) {
			clusters.add(c);
			if (c.isMembraneAssoc()) {
				memClusters.add(c);
			} else {
				cytoClusters.add(c);
			}
		}
	}
	
	public void addFocus(Focus f) {
		if (this.equals(f.getCluster().getParent())) {
			foci.add(f);
			if (f.getCluster().isMembraneAssoc()) {
				memFoci.add(f);
			} else {
				cytoFoci.add(f);
			}
		}
	}
}
